%% Cross-Correlation

CrossCor=real(ifft2(fft2(Spins).*conj(fft2(Spins))));
imshow(CrossCor,[],'InitialMagnification',400)

%Shift zero to center
CCS=fftshift(CrossCor);
imshow(CCS,[],'InitialMagnification',400)
    
%% Freely-Jointed Chain

N=1000;

%Creating a 3d vector with random orientation (one of many ways)
X=rand(N,1)-.5;
Y=rand(N,1)-.5;
Z=rand(N,1)-.5;

%normalize
L_xyz=sqrt(sum(X.^2+Y.^2+Z.^2,2));
Xnorm=X./L_xyz;
Ynorm=Y./L_xyz;
Znorm=Z./L_xyz;

%Check to see if it is uniform on sphere
figure
plot3(Xnorm,Ynorm,Znorm,'.')
xlabel('X')
ylabel('Y')
zlabel('Z')

%Build chain
XChain=cumsum(Xnorm);
YChain=cumsum(Ynorm);
ZChain=cumsum(Znorm);

%Plot chain
figure
plot3(XChain,YChain,ZChain,'linewidth',2)
xlabel('X')
ylabel('Y')
zlabel('Z')
axis equal

